package com.industrial.loweff.service.impl;

import com.industrial.loweff.domain.*;
import com.industrial.loweff.mapper.LowEffCompanyMapper;
import com.industrial.loweff.service.ILowEffCompanyService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class LowEffCompanyServiceImpl implements ILowEffCompanyService {

    @Autowired
    private LowEffCompanyMapper lowEffCompanyMapper;

    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 查询列表
     *
     * @param params
     * @return
     */
    @Override
    public List<LowEfficiencyBenefitEvaluation> list(LowEfficiencyBenefitEvaluation params) {
        List<LowEfficiencyBenefitEvaluation> list = lowEffCompanyMapper.list(params);
        for(LowEfficiencyBenefitEvaluation temp : list){
            String province = temp.getProvince();
            String city = temp.getCity();
            String county = temp.getCounty();

            if(StringUtils.isNotBlank(province)){
                String provinceStr = redisTemplate.opsForValue().get("area:" + province);
                temp.setProvince(provinceStr);
            }

            if(StringUtils.isNotBlank(city)){
                String cityStr = redisTemplate.opsForValue().get("area:" + city);
                temp.setCity(cityStr);
            }

            if(StringUtils.isNotBlank(county)){
                String countyStr = redisTemplate.opsForValue().get("area:" + county);
                temp.setCounty(countyStr);
            }
        }
        return list;
    }

    /**
     * 查询诊断信息
     *
     * @param params
     * @return
     */
    @Override
    public Map<String, Object> queryZd(LowEfficiencyBenefitEvaluation params) {
        LowEfficiencyBenefitEvaluation l = lowEffCompanyMapper.selectPreMuBenefitEvaluationById(params.getId());
        if(l != null && StringUtils.isNotBlank(l.getMjLevel())){
            String mjLevel = l.getMjLevel();
            List<LowEfficiencyBenefitEvaluation> r = lowEffCompanyMapper.selectPreMuBenefitEvaluationByMjLevel(mjLevel);
            int size = r.size();
            List<BigDecimal> avgs = new ArrayList<>();
            List<BigDecimal> currentValue = new ArrayList<>();
            List<String> sfDb = new ArrayList<>();
            if(size != 0){
                //单位用地税收
                BigDecimal ydssZh = r.stream().filter(k -> !(k == null)).map(k -> k.getScore1() == null ? BigDecimal.ZERO : k.getScore1()).reduce(BigDecimal::add).get();
                BigDecimal ydssPj = ydssZh.divide(BigDecimal.valueOf(size), 2, BigDecimal.ROUND_HALF_UP);
                avgs.add(ydssPj);
                BigDecimal score1 = l.getScore1() == null ? BigDecimal.ZERO : l.getScore1();
                if(l.getScore1() == null){
                    sfDb.add("-");
                }else{
                    if(score1.compareTo(ydssPj) == 1 || score1.compareTo(ydssPj) == 0){
                        sfDb.add("已达标");
                    }else{
                        sfDb.add("未达标");
                    }
                }


                //单位能耗销售收入
                BigDecimal dwnhZh = r.stream().filter(k -> !(k == null)).map(k -> k.getScore2() == null ? BigDecimal.ZERO : k.getScore2()).reduce(BigDecimal::add).get();
                BigDecimal dwnhPj = dwnhZh.divide(BigDecimal.valueOf(size), 2, BigDecimal.ROUND_HALF_UP);
                avgs.add(dwnhPj);
                BigDecimal score2 = l.getScore2() == null ? BigDecimal.ZERO : l.getScore2();
                if(l.getScore2() == null){
                    sfDb.add("-");
                }else{
                    if(score2.compareTo(dwnhPj) == 1 || score2.compareTo(dwnhPj) == 0){
                        sfDb.add("已达标");
                    }else{
                        sfDb.add("未达标");
                    }
                }


                //单位污染物排放销售收入
                BigDecimal dwwrwZh = r.stream().filter(k -> !(k == null)).map(k -> k.getScore3() == null ? BigDecimal.ZERO : k.getScore3()).reduce(BigDecimal::add).get();
                BigDecimal dwwrwPj = dwwrwZh.divide(BigDecimal.valueOf(size), 2, BigDecimal.ROUND_HALF_UP);
                avgs.add(dwwrwPj);
                BigDecimal score3 = l.getScore3() == null ? BigDecimal.ZERO : l.getScore3();
                if(l.getScore3() == null){
                    sfDb.add("-");
                }else{
                    if(score3.compareTo(dwwrwPj) == 1 || score3.compareTo(dwwrwPj) == 0){
                        sfDb.add("已达标");
                    }else{
                        sfDb.add("未达标");
                    }
                }

                //研发经费投入强度
                BigDecimal yfjftrZh = r.stream().filter(k -> !(k == null)).map(k -> k.getScore4() == null ? BigDecimal.ZERO : k.getScore4()).reduce(BigDecimal::add).get();
                BigDecimal yfjftrPj = yfjftrZh.divide(BigDecimal.valueOf(size), 2, BigDecimal.ROUND_HALF_UP);
                avgs.add(yfjftrPj);
                BigDecimal score4 = l.getScore4() == null ? BigDecimal.ZERO : l.getScore4();
                if(l.getScore4() == null){
                    sfDb.add("-");
                }else{
                    if(score4.compareTo(yfjftrPj) == 1 || score4.compareTo(yfjftrPj) == 0){
                        sfDb.add("已达标");
                    }else{
                        sfDb.add("未达标");
                    }
                }

                //全员劳动生产率
                BigDecimal qyldsclZh = r.stream().filter(k -> !(k == null)).map(k -> k.getScore5() == null ? BigDecimal.ZERO : k.getScore5()).reduce(BigDecimal::add).get();
                BigDecimal qyldsclPj = qyldsclZh.divide(BigDecimal.valueOf(size), 2, BigDecimal.ROUND_HALF_UP);
                avgs.add(qyldsclPj);
                BigDecimal score5 = l.getScore5() == null ? BigDecimal.ZERO : l.getScore5();
                if(l.getScore5() == null){
                    sfDb.add("-");
                }else{
                    if(score5.compareTo(qyldsclPj) == 1 || score5.compareTo(qyldsclPj) == 0){
                        sfDb.add("已达标");
                    }else{
                        sfDb.add("未达标");
                    }
                }

                //单位用地销售收入
                BigDecimal dwydxsZh = r.stream().filter(k -> !(k == null)).map(k -> k.getScore7() == null ? BigDecimal.ZERO : k.getScore7()).reduce(BigDecimal::add).get();
                BigDecimal dwydxsPj = dwydxsZh.divide(BigDecimal.valueOf(size), 2, BigDecimal.ROUND_HALF_UP);
                avgs.add(dwydxsPj);
                BigDecimal score7 = l.getScore7() == null ? BigDecimal.ZERO : l.getScore7();
                if(l.getScore7() == null){
                    sfDb.add("-");
                }else{
                    if(score7.compareTo(dwydxsPj) == 1 || score7.compareTo(dwydxsPj) == 0){
                        sfDb.add("已达标");
                    }else{
                        sfDb.add("未达标");
                    }
                }

            }
            currentValue.add(l.getScore1());
            currentValue.add(l.getScore2());
            currentValue.add(l.getScore3());
            currentValue.add(l.getScore4());
            currentValue.add(l.getScore5());
            currentValue.add(l.getScore7());

            Map<String,Object> result = new HashMap<>();
            result.put("avgs",avgs);
            result.put("currentValue",currentValue);
            result.put("sfDb",sfDb);
            return result;
        }
        Map<String,Object> result = new HashMap<>();
        return result;
    }

    /**
     * 查询单位用地税收监测
     *
     * @param jcQueryParam
     * @return
     */
    @Override
    public List<JcResVo> dwydssjcTable(JcQueryParam jcQueryParam) {

        //查询近一年单位用地税收监测
        List<JcQueryDo> jynData = lowEffCompanyMapper.queryDwydssJyn(jcQueryParam.getYiYear(),jcQueryParam);
        //查询近二年单位用地税收监测
        List<JcQueryDo> jenData = lowEffCompanyMapper.queryDwydssJyn(jcQueryParam.getLiangYear(),jcQueryParam);
        //查询近三年单位用地税收监测
        List<JcQueryDo> jsnData = lowEffCompanyMapper.queryDwydssJyn(jcQueryParam.getSanYear(),jcQueryParam);
        List<JcQueryDo> jsinData = lowEffCompanyMapper.queryDwydssJyn(jcQueryParam.getSiYear(),jcQueryParam);
        List<JcQueryDo> jwnData = lowEffCompanyMapper.queryDwydssJyn(jcQueryParam.getWuYear(),jcQueryParam);

        //将List集合转换成Map
        Map<String,String> jynMap = new HashMap<>();
        Map<String,String> jenMap = new HashMap<>();
        Map<String,String> jsnMap = new HashMap<>();
        Map<String,String> jsinMap = new HashMap<>();
        Map<String,String> jwunMap = new HashMap<>();
        if(jynData != null && !jynData.isEmpty()){
            jynMap = jynData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jenData != null && !jenData.isEmpty()){
            jenMap = jenData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jsnData != null && !jsnData.isEmpty()){
            jsnMap = jsnData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }

        if(jsinData != null && !jsinData.isEmpty()){
            jsinMap = jsinData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jwnData != null && !jwnData.isEmpty()){
            jwunMap = jwnData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }

        //查询16地市
        List<LowArea> cityList = lowEffCompanyMapper.selectCityInfo(jcQueryParam);

        Map<String, String> cityMap = cityList.stream().collect(Collectors.toMap(LowArea::getAreaCode, LowArea::getBaseName,(oldValue, newValue) -> oldValue, TreeMap::new));

        List<JcResVo> result = new ArrayList<>();

        for(Map.Entry<String,String> temp : cityMap.entrySet()){
            String value = temp.getValue();

            JcResVo tempJcRes = new JcResVo();
            tempJcRes.setCity(value);
            tempJcRes.setJyn(jynMap.get(value));
            tempJcRes.setJen(jenMap.get(value));
            tempJcRes.setJsn(jsnMap.get(value));
            tempJcRes.setJsin(jsinMap.get(value));
            tempJcRes.setJwn(jwunMap.get(value));
            result.add(tempJcRes);
        }
        return result;
    }




    /**
     * 查询单位用地税收Charts
     * @param jcQueryParam
     * @return
     */
    @Override
    public Map<String, Object> queryDwydssjcCharts(JcQueryParam jcQueryParam) {

        //查询YiYear上一年的数据，为了计算同比
        Integer preYear = Integer.valueOf(jcQueryParam.getWuYear()) - 1;
        JcQueryDo preData = lowEffCompanyMapper.queryDwydssJynCharts(String.valueOf(preYear),jcQueryParam);

        //查询近一年单位用地税收监测
        JcQueryDo jynData = lowEffCompanyMapper.queryDwydssJynCharts(jcQueryParam.getYiYear(),jcQueryParam);
        //查询近二年单位用地税收监测
        JcQueryDo jenData = lowEffCompanyMapper.queryDwydssJynCharts(jcQueryParam.getLiangYear(),jcQueryParam);
        //查询近三年单位用地税收监测
        JcQueryDo jsnData = lowEffCompanyMapper.queryDwydssJynCharts(jcQueryParam.getSanYear(),jcQueryParam);
        JcQueryDo jsinData = lowEffCompanyMapper.queryDwydssJynCharts(jcQueryParam.getSiYear(),jcQueryParam);
        JcQueryDo jwnData = lowEffCompanyMapper.queryDwydssJynCharts(jcQueryParam.getWuYear(),jcQueryParam);

        List<String> xAxis = new ArrayList<>();
        List<String> zzCharts = new ArrayList<>();
        List<BigDecimal> tb = new ArrayList<>();
        if(jynData != null){
            String yiYear = jcQueryParam.getYiYear();
            xAxis.add(yiYear);
            String value = jynData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jenData == null ? BigDecimal.ZERO : new BigDecimal(jenData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String yiYear = jcQueryParam.getYiYear();
            xAxis.add(yiYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jenData != null){
            String liangYear = jcQueryParam.getLiangYear();
            xAxis.add(liangYear);
            String value = jenData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jsnData == null ? BigDecimal.ZERO : new BigDecimal(jsnData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String liangYear = jcQueryParam.getLiangYear();
            xAxis.add(liangYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jsnData != null){
            String sanYear = jcQueryParam.getSanYear();
            xAxis.add(sanYear);
            String value = jsnData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue =  jsinData == null ? BigDecimal.ZERO : new BigDecimal(jsinData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String sanYear = jcQueryParam.getSanYear();
            xAxis.add(sanYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jsinData != null){
            String yiYear = jcQueryParam.getSiYear();
            xAxis.add(yiYear);
            String value = jsinData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jwnData == null ? BigDecimal.ZERO : new BigDecimal(jwnData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }

        }else{
            String yiYear = jcQueryParam.getSiYear();
            xAxis.add(yiYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jwnData != null){
            String wuYear = jcQueryParam.getWuYear();
            xAxis.add(wuYear);
            String value = jwnData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = preData == null ? BigDecimal.ZERO :  new BigDecimal(preData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }

        }else{
            String wuYear = jcQueryParam.getWuYear();
            xAxis.add(wuYear);
            zzCharts.add("0");
            tb.add(null);
        }

        Map<String,Object> result = new HashMap<>();
        result.put("X",xAxis);
        result.put("zzCharts",zzCharts);
        result.put("tb",tb);
        return result;
    }


    /**
     * 查询单位能耗销售收
     *
     * @param jcQueryParam
     * @return
     */
    @Override
    public List<JcResVo> dwnhxssrTable(JcQueryParam jcQueryParam) {
        //查询近一年单位用地税收监测
        List<JcQueryDo> jynData = lowEffCompanyMapper.queryDwnhxssr(jcQueryParam.getYiYear(),jcQueryParam);
        //查询近二年单位用地税收监测
        List<JcQueryDo> jenData = lowEffCompanyMapper.queryDwnhxssr(jcQueryParam.getLiangYear(),jcQueryParam);
        //查询近三年单位用地税收监测
        List<JcQueryDo> jsnData = lowEffCompanyMapper.queryDwnhxssr(jcQueryParam.getSanYear(),jcQueryParam);
        List<JcQueryDo> jsinData = lowEffCompanyMapper.queryDwnhxssr(jcQueryParam.getSiYear(),jcQueryParam);
        List<JcQueryDo> jwnData = lowEffCompanyMapper.queryDwnhxssr(jcQueryParam.getWuYear(),jcQueryParam);

        //将List集合转换成Map
        Map<String,String> jynMap = new HashMap<>();
        Map<String,String> jenMap = new HashMap<>();
        Map<String,String> jsnMap = new HashMap<>();
        Map<String,String> jsinMap = new HashMap<>();
        Map<String,String> jwunMap = new HashMap<>();
        if(jynData != null && !jynData.isEmpty()){
            jynMap = jynData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jenData != null && !jenData.isEmpty()){
            jenMap = jenData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jsnData != null && !jsnData.isEmpty()){
            jsnMap = jsnData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }

        if(jsinData != null && !jsinData.isEmpty()){
            jsinMap = jsinData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jwnData != null && !jwnData.isEmpty()){
            jwunMap = jwnData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }

        //查询16地市
        List<LowArea> cityList = lowEffCompanyMapper.selectCityInfo(jcQueryParam);

        Map<String, String> cityMap = cityList.stream().collect(Collectors.toMap(LowArea::getAreaCode, LowArea::getBaseName,(oldValue, newValue) -> oldValue, TreeMap::new));

        List<JcResVo> result = new ArrayList<>();

        for(Map.Entry<String,String> temp : cityMap.entrySet()){
            String value = temp.getValue();

            JcResVo tempJcRes = new JcResVo();
            tempJcRes.setCity(value);
            tempJcRes.setJyn(jynMap.get(value));
            tempJcRes.setJen(jenMap.get(value));
            tempJcRes.setJsn(jsnMap.get(value));
            tempJcRes.setJsin(jsinMap.get(value));
            tempJcRes.setJwn(jwunMap.get(value));
            result.add(tempJcRes);
        }
        return result;
    }

    /**
     * 查询单位能耗销售收入Charts
     *
     * @param jcQueryParam
     * @return
     */
    @Override
    public Map<String, Object> queryDwnhxssrCharts(JcQueryParam jcQueryParam) {
        //查询YiYear上一年的数据，为了计算同比
        Integer preYear = Integer.valueOf(jcQueryParam.getWuYear()) - 1;
        JcQueryDo preData = lowEffCompanyMapper.queryDwnhxssrCharts(String.valueOf(preYear),jcQueryParam);

        //查询近一年单位用地税收监测
        JcQueryDo jynData = lowEffCompanyMapper.queryDwnhxssrCharts(jcQueryParam.getYiYear(),jcQueryParam);
        //查询近二年单位用地税收监测
        JcQueryDo jenData = lowEffCompanyMapper.queryDwnhxssrCharts(jcQueryParam.getLiangYear(),jcQueryParam);
        //查询近三年单位用地税收监测
        JcQueryDo jsnData = lowEffCompanyMapper.queryDwnhxssrCharts(jcQueryParam.getSanYear(),jcQueryParam);
        JcQueryDo jsinData = lowEffCompanyMapper.queryDwnhxssrCharts(jcQueryParam.getSiYear(),jcQueryParam);
        JcQueryDo jwnData = lowEffCompanyMapper.queryDwnhxssrCharts(jcQueryParam.getWuYear(),jcQueryParam);

        List<String> xAxis = new ArrayList<>();
        List<String> zzCharts = new ArrayList<>();
        List<BigDecimal> tb = new ArrayList<>();
        if(jynData != null){
            String yiYear = jcQueryParam.getYiYear();
            xAxis.add(yiYear);
            String value = jynData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jenData == null ? BigDecimal.ZERO : new BigDecimal(jenData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String yiYear = jcQueryParam.getYiYear();
            xAxis.add(yiYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jenData != null){
            String liangYear = jcQueryParam.getLiangYear();
            xAxis.add(liangYear);
            String value = jenData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jsnData == null ? BigDecimal.ZERO : new BigDecimal(jsnData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String liangYear = jcQueryParam.getLiangYear();
            xAxis.add(liangYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jsnData != null){
            String sanYear = jcQueryParam.getSanYear();
            xAxis.add(sanYear);
            String value = jsnData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue =  jsinData == null ? BigDecimal.ZERO : new BigDecimal(jsinData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String sanYear = jcQueryParam.getSanYear();
            xAxis.add(sanYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jsinData != null){
            String yiYear = jcQueryParam.getSiYear();
            xAxis.add(yiYear);
            String value = jsinData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jwnData == null ? BigDecimal.ZERO : new BigDecimal(jwnData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }

        }else{
            String yiYear = jcQueryParam.getSiYear();
            xAxis.add(yiYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jwnData != null){
            String wuYear = jcQueryParam.getWuYear();
            xAxis.add(wuYear);
            String value = jwnData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = preData == null ? BigDecimal.ZERO :  new BigDecimal(preData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }

        }else{
            String wuYear = jcQueryParam.getWuYear();
            xAxis.add(wuYear);
            zzCharts.add("0");
            tb.add(null);
        }

        Map<String,Object> result = new HashMap<>();
        result.put("X",xAxis);
        result.put("zzCharts",zzCharts);
        result.put("tb",tb);
        return result;
    }

    /**
     * 查询单位污染排放销售收入
     *
     * @param jcQueryParam
     * @return
     */
    @Override
    public List<JcResVo> dwwrpfxssrTable(JcQueryParam jcQueryParam) {
        //查询近一年单位用地税收监测
        List<JcQueryDo> jynData = lowEffCompanyMapper.queryDwwrpfxssr(jcQueryParam.getYiYear(),jcQueryParam);
        //查询近二年单位用地税收监测
        List<JcQueryDo> jenData = lowEffCompanyMapper.queryDwwrpfxssr(jcQueryParam.getLiangYear(),jcQueryParam);
        //查询近三年单位用地税收监测
        List<JcQueryDo> jsnData = lowEffCompanyMapper.queryDwwrpfxssr(jcQueryParam.getSanYear(),jcQueryParam);
        List<JcQueryDo> jsinData = lowEffCompanyMapper.queryDwwrpfxssr(jcQueryParam.getSiYear(),jcQueryParam);
        List<JcQueryDo> jwnData = lowEffCompanyMapper.queryDwwrpfxssr(jcQueryParam.getWuYear(),jcQueryParam);

        //将List集合转换成Map
        Map<String,String> jynMap = new HashMap<>();
        Map<String,String> jenMap = new HashMap<>();
        Map<String,String> jsnMap = new HashMap<>();
        Map<String,String> jsinMap = new HashMap<>();
        Map<String,String> jwunMap = new HashMap<>();
        if(jynData != null && !jynData.isEmpty()){
            jynMap = jynData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jenData != null && !jenData.isEmpty()){
            jenMap = jenData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jsnData != null && !jsnData.isEmpty()){
            jsnMap = jsnData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }

        if(jsinData != null && !jsinData.isEmpty()){
            jsinMap = jsinData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jwnData != null && !jwnData.isEmpty()){
            jwunMap = jwnData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }

        //查询16地市
        List<LowArea> cityList = lowEffCompanyMapper.selectCityInfo(jcQueryParam);

        Map<String, String> cityMap = cityList.stream().collect(Collectors.toMap(LowArea::getAreaCode, LowArea::getBaseName,(oldValue, newValue) -> oldValue, TreeMap::new));

        List<JcResVo> result = new ArrayList<>();

        for(Map.Entry<String,String> temp : cityMap.entrySet()){
            String value = temp.getValue();

            JcResVo tempJcRes = new JcResVo();
            tempJcRes.setCity(value);
            tempJcRes.setJyn(jynMap.get(value));
            tempJcRes.setJen(jenMap.get(value));
            tempJcRes.setJsn(jsnMap.get(value));
            tempJcRes.setJsin(jsinMap.get(value));
            tempJcRes.setJwn(jwunMap.get(value));
            result.add(tempJcRes);
        }
        return result;
    }

    /**
     * 查询单位污染排放销售收入Charts
     *
     * @param jcQueryParam
     * @return
     */
    @Override
    public Map<String, Object> queryDwwrpfxssrCharts(JcQueryParam jcQueryParam) {
        //查询YiYear上一年的数据，为了计算同比
        Integer preYear = Integer.valueOf(jcQueryParam.getWuYear()) - 1;
        JcQueryDo preData = lowEffCompanyMapper.queryDwwrpfxssrCharts(String.valueOf(preYear),jcQueryParam);

        //查询近一年单位用地税收监测
        JcQueryDo jynData = lowEffCompanyMapper.queryDwwrpfxssrCharts(jcQueryParam.getYiYear(),jcQueryParam);
        //查询近二年单位用地税收监测
        JcQueryDo jenData = lowEffCompanyMapper.queryDwwrpfxssrCharts(jcQueryParam.getLiangYear(),jcQueryParam);
        //查询近三年单位用地税收监测
        JcQueryDo jsnData = lowEffCompanyMapper.queryDwwrpfxssrCharts(jcQueryParam.getSanYear(),jcQueryParam);
        JcQueryDo jsinData = lowEffCompanyMapper.queryDwwrpfxssrCharts(jcQueryParam.getSiYear(),jcQueryParam);
        JcQueryDo jwnData = lowEffCompanyMapper.queryDwwrpfxssrCharts(jcQueryParam.getWuYear(),jcQueryParam);

        List<String> xAxis = new ArrayList<>();
        List<String> zzCharts = new ArrayList<>();
        List<BigDecimal> tb = new ArrayList<>();
        if(jynData != null){
            String yiYear = jcQueryParam.getYiYear();
            xAxis.add(yiYear);
            String value = jynData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jenData == null ? BigDecimal.ZERO : new BigDecimal(jenData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String yiYear = jcQueryParam.getYiYear();
            xAxis.add(yiYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jenData != null){
            String liangYear = jcQueryParam.getLiangYear();
            xAxis.add(liangYear);
            String value = jenData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jsnData == null ? BigDecimal.ZERO : new BigDecimal(jsnData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String liangYear = jcQueryParam.getLiangYear();
            xAxis.add(liangYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jsnData != null){
            String sanYear = jcQueryParam.getSanYear();
            xAxis.add(sanYear);
            String value = jsnData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue =  jsinData == null ? BigDecimal.ZERO : new BigDecimal(jsinData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String sanYear = jcQueryParam.getSanYear();
            xAxis.add(sanYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jsinData != null){
            String yiYear = jcQueryParam.getSiYear();
            xAxis.add(yiYear);
            String value = jsinData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jwnData == null ? BigDecimal.ZERO : new BigDecimal(jwnData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }

        }else{
            String yiYear = jcQueryParam.getSiYear();
            xAxis.add(yiYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jwnData != null){
            String wuYear = jcQueryParam.getWuYear();
            xAxis.add(wuYear);
            String value = jwnData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = preData == null ? BigDecimal.ZERO :  new BigDecimal(preData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }

        }else{
            String wuYear = jcQueryParam.getWuYear();
            xAxis.add(wuYear);
            zzCharts.add("0");
            tb.add(null);
        }

        Map<String,Object> result = new HashMap<>();
        result.put("X",xAxis);
        result.put("zzCharts",zzCharts);
        result.put("tb",tb);
        return result;
    }

    /**
     * 查询研发经费投入
     *
     * @param jcQueryParam
     * @return
     */
    @Override
    public List<JcResVo> yfjftrTable(JcQueryParam jcQueryParam) {
        //查询近一年单位用地税收监测
        List<JcQueryDo> jynData = lowEffCompanyMapper.queryYfjftr(jcQueryParam.getYiYear(),jcQueryParam);
        //查询近二年单位用地税收监测
        List<JcQueryDo> jenData = lowEffCompanyMapper.queryYfjftr(jcQueryParam.getLiangYear(),jcQueryParam);
        //查询近三年单位用地税收监测
        List<JcQueryDo> jsnData = lowEffCompanyMapper.queryYfjftr(jcQueryParam.getSanYear(),jcQueryParam);
        List<JcQueryDo> jsinData = lowEffCompanyMapper.queryYfjftr(jcQueryParam.getSiYear(),jcQueryParam);
        List<JcQueryDo> jwnData = lowEffCompanyMapper.queryYfjftr(jcQueryParam.getWuYear(),jcQueryParam);

        //将List集合转换成Map
        Map<String,String> jynMap = new HashMap<>();
        Map<String,String> jenMap = new HashMap<>();
        Map<String,String> jsnMap = new HashMap<>();
        Map<String,String> jsinMap = new HashMap<>();
        Map<String,String> jwunMap = new HashMap<>();
        if(jynData != null && !jynData.isEmpty()){
            jynMap = jynData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jenData != null && !jenData.isEmpty()){
            jenMap = jenData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jsnData != null && !jsnData.isEmpty()){
            jsnMap = jsnData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }

        if(jsinData != null && !jsinData.isEmpty()){
            jsinMap = jsinData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jwnData != null && !jwnData.isEmpty()){
            jwunMap = jwnData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }

        //查询16地市
        List<LowArea> cityList = lowEffCompanyMapper.selectCityInfo(jcQueryParam);

        Map<String, String> cityMap = cityList.stream().collect(Collectors.toMap(LowArea::getAreaCode, LowArea::getBaseName,(oldValue, newValue) -> oldValue, TreeMap::new));

        List<JcResVo> result = new ArrayList<>();

        for(Map.Entry<String,String> temp : cityMap.entrySet()){
            String value = temp.getValue();

            JcResVo tempJcRes = new JcResVo();
            tempJcRes.setCity(value);
            tempJcRes.setJyn(jynMap.get(value));
            tempJcRes.setJen(jenMap.get(value));
            tempJcRes.setJsn(jsnMap.get(value));
            tempJcRes.setJsin(jsinMap.get(value));
            tempJcRes.setJwn(jwunMap.get(value));
            result.add(tempJcRes);
        }
        return result;
    }

    /**
     * 查询研发经费投入Charts
     *
     * @param jcQueryParam
     * @return
     */
    @Override
    public Map<String, Object> queryYfjftrCharts(JcQueryParam jcQueryParam) {
        //查询YiYear上一年的数据，为了计算同比
        Integer preYear = Integer.valueOf(jcQueryParam.getWuYear()) - 1;
        JcQueryDo preData = lowEffCompanyMapper.queryYfjftrCharts(String.valueOf(preYear),jcQueryParam);

        //查询近一年单位用地税收监测
        JcQueryDo jynData = lowEffCompanyMapper.queryYfjftrCharts(jcQueryParam.getYiYear(),jcQueryParam);
        //查询近二年单位用地税收监测
        JcQueryDo jenData = lowEffCompanyMapper.queryYfjftrCharts(jcQueryParam.getLiangYear(),jcQueryParam);
        //查询近三年单位用地税收监测
        JcQueryDo jsnData = lowEffCompanyMapper.queryYfjftrCharts(jcQueryParam.getSanYear(),jcQueryParam);
        JcQueryDo jsinData = lowEffCompanyMapper.queryYfjftrCharts(jcQueryParam.getSiYear(),jcQueryParam);
        JcQueryDo jwnData = lowEffCompanyMapper.queryYfjftrCharts(jcQueryParam.getWuYear(),jcQueryParam);

        List<String> xAxis = new ArrayList<>();
        List<String> zzCharts = new ArrayList<>();
        List<BigDecimal> tb = new ArrayList<>();
        if(jynData != null){
            String yiYear = jcQueryParam.getYiYear();
            xAxis.add(yiYear);
            String value = jynData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jenData == null ? BigDecimal.ZERO : new BigDecimal(jenData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String yiYear = jcQueryParam.getYiYear();
            xAxis.add(yiYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jenData != null){
            String liangYear = jcQueryParam.getLiangYear();
            xAxis.add(liangYear);
            String value = jenData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jsnData == null ? BigDecimal.ZERO : new BigDecimal(jsnData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String liangYear = jcQueryParam.getLiangYear();
            xAxis.add(liangYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jsnData != null){
            String sanYear = jcQueryParam.getSanYear();
            xAxis.add(sanYear);
            String value = jsnData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue =  jsinData == null ? BigDecimal.ZERO : new BigDecimal(jsinData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String sanYear = jcQueryParam.getSanYear();
            xAxis.add(sanYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jsinData != null){
            String yiYear = jcQueryParam.getSiYear();
            xAxis.add(yiYear);
            String value = jsinData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jwnData == null ? BigDecimal.ZERO : new BigDecimal(jwnData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }

        }else{
            String yiYear = jcQueryParam.getSiYear();
            xAxis.add(yiYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jwnData != null){
            String wuYear = jcQueryParam.getWuYear();
            xAxis.add(wuYear);
            String value = jwnData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = preData == null ? BigDecimal.ZERO :  new BigDecimal(preData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }

        }else{
            String wuYear = jcQueryParam.getWuYear();
            xAxis.add(wuYear);
            zzCharts.add("0");
            tb.add(null);
        }

        Map<String,Object> result = new HashMap<>();
        result.put("X",xAxis);
        result.put("zzCharts",zzCharts);
        result.put("tb",tb);
        return result;
    }

    /**
     * 查询全员劳动生产力
     *
     * @param jcQueryParam
     * @return
     */
    @Override
    public List<JcResVo> qyldsclTable(JcQueryParam jcQueryParam) {
        //查询近一年单位用地税收监测
        List<JcQueryDo> jynData = lowEffCompanyMapper.queryQyldscl(jcQueryParam.getYiYear(),jcQueryParam);
        //查询近二年单位用地税收监测
        List<JcQueryDo> jenData = lowEffCompanyMapper.queryQyldscl(jcQueryParam.getLiangYear(),jcQueryParam);
        //查询近三年单位用地税收监测
        List<JcQueryDo> jsnData = lowEffCompanyMapper.queryQyldscl(jcQueryParam.getSanYear(),jcQueryParam);
        List<JcQueryDo> jsinData = lowEffCompanyMapper.queryQyldscl(jcQueryParam.getSiYear(),jcQueryParam);
        List<JcQueryDo> jwnData = lowEffCompanyMapper.queryQyldscl(jcQueryParam.getWuYear(),jcQueryParam);

        //将List集合转换成Map
        Map<String,String> jynMap = new HashMap<>();
        Map<String,String> jenMap = new HashMap<>();
        Map<String,String> jsnMap = new HashMap<>();
        Map<String,String> jsinMap = new HashMap<>();
        Map<String,String> jwunMap = new HashMap<>();
        if(jynData != null && !jynData.isEmpty()){
            jynMap = jynData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jenData != null && !jenData.isEmpty()){
            jenMap = jenData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jsnData != null && !jsnData.isEmpty()){
            jsnMap = jsnData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }

        if(jsinData != null && !jsinData.isEmpty()){
            jsinMap = jsinData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jwnData != null && !jwnData.isEmpty()){
            jwunMap = jwnData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }

        //查询16地市
        List<LowArea> cityList = lowEffCompanyMapper.selectCityInfo(jcQueryParam);

        Map<String, String> cityMap = cityList.stream().collect(Collectors.toMap(LowArea::getAreaCode, LowArea::getBaseName,(oldValue, newValue) -> oldValue, TreeMap::new));

        List<JcResVo> result = new ArrayList<>();

        for(Map.Entry<String,String> temp : cityMap.entrySet()){
            String value = temp.getValue();

            JcResVo tempJcRes = new JcResVo();
            tempJcRes.setCity(value);
            tempJcRes.setJyn(jynMap.get(value));
            tempJcRes.setJen(jenMap.get(value));
            tempJcRes.setJsn(jsnMap.get(value));
            tempJcRes.setJsin(jsinMap.get(value));
            tempJcRes.setJwn(jwunMap.get(value));
            result.add(tempJcRes);
        }
        return result;
    }

    /**
     * 查询全员劳动生产力Charts
     *
     * @param jcQueryParam
     * @return
     */
    @Override
    public Map<String, Object> queryQyldsclCharts(JcQueryParam jcQueryParam) {
        //查询YiYear上一年的数据，为了计算同比
        Integer preYear = Integer.valueOf(jcQueryParam.getWuYear()) - 1;
        JcQueryDo preData = lowEffCompanyMapper.queryQyldsclCharts(String.valueOf(preYear),jcQueryParam);

        //查询近一年单位用地税收监测
        JcQueryDo jynData = lowEffCompanyMapper.queryQyldsclCharts(jcQueryParam.getYiYear(),jcQueryParam);
        //查询近二年单位用地税收监测
        JcQueryDo jenData = lowEffCompanyMapper.queryQyldsclCharts(jcQueryParam.getLiangYear(),jcQueryParam);
        //查询近三年单位用地税收监测
        JcQueryDo jsnData = lowEffCompanyMapper.queryQyldsclCharts(jcQueryParam.getSanYear(),jcQueryParam);
        JcQueryDo jsinData = lowEffCompanyMapper.queryQyldsclCharts(jcQueryParam.getSiYear(),jcQueryParam);
        JcQueryDo jwnData = lowEffCompanyMapper.queryQyldsclCharts(jcQueryParam.getWuYear(),jcQueryParam);

        List<String> xAxis = new ArrayList<>();
        List<String> zzCharts = new ArrayList<>();
        List<BigDecimal> tb = new ArrayList<>();
        if(jynData != null){
            String yiYear = jcQueryParam.getYiYear();
            xAxis.add(yiYear);
            String value = jynData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jenData == null ? BigDecimal.ZERO : new BigDecimal(jenData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String yiYear = jcQueryParam.getYiYear();
            xAxis.add(yiYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jenData != null){
            String liangYear = jcQueryParam.getLiangYear();
            xAxis.add(liangYear);
            String value = jenData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jsnData == null ? BigDecimal.ZERO : new BigDecimal(jsnData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String liangYear = jcQueryParam.getLiangYear();
            xAxis.add(liangYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jsnData != null){
            String sanYear = jcQueryParam.getSanYear();
            xAxis.add(sanYear);
            String value = jsnData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue =  jsinData == null ? BigDecimal.ZERO : new BigDecimal(jsinData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String sanYear = jcQueryParam.getSanYear();
            xAxis.add(sanYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jsinData != null){
            String yiYear = jcQueryParam.getSiYear();
            xAxis.add(yiYear);
            String value = jsinData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jwnData == null ? BigDecimal.ZERO : new BigDecimal(jwnData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }

        }else{
            String yiYear = jcQueryParam.getSiYear();
            xAxis.add(yiYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jwnData != null){
            String wuYear = jcQueryParam.getWuYear();
            xAxis.add(wuYear);
            String value = jwnData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = preData == null ? BigDecimal.ZERO :  new BigDecimal(preData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }

        }else{
            String wuYear = jcQueryParam.getWuYear();
            xAxis.add(wuYear);
            zzCharts.add("0");
            tb.add(null);
        }

        Map<String,Object> result = new HashMap<>();
        result.put("X",xAxis);
        result.put("zzCharts",zzCharts);
        result.put("tb",tb);
        return result;
    }

    /**
     * 查询单位用地销售
     *
     * @param jcQueryParam
     * @return
     */
    @Override
    public List<JcResVo> dwysxssrTable(JcQueryParam jcQueryParam) {
        //查询近一年单位用地税收监测
        List<JcQueryDo> jynData = lowEffCompanyMapper.queryDwysxssr(jcQueryParam.getYiYear(),jcQueryParam);
        //查询近二年单位用地税收监测
        List<JcQueryDo> jenData = lowEffCompanyMapper.queryDwysxssr(jcQueryParam.getLiangYear(),jcQueryParam);
        //查询近三年单位用地税收监测
        List<JcQueryDo> jsnData = lowEffCompanyMapper.queryDwysxssr(jcQueryParam.getSanYear(),jcQueryParam);
        List<JcQueryDo> jsinData = lowEffCompanyMapper.queryDwysxssr(jcQueryParam.getSiYear(),jcQueryParam);
        List<JcQueryDo> jwnData = lowEffCompanyMapper.queryDwysxssr(jcQueryParam.getWuYear(),jcQueryParam);

        //将List集合转换成Map
        Map<String,String> jynMap = new HashMap<>();
        Map<String,String> jenMap = new HashMap<>();
        Map<String,String> jsnMap = new HashMap<>();
        Map<String,String> jsinMap = new HashMap<>();
        Map<String,String> jwunMap = new HashMap<>();
        if(jynData != null && !jynData.isEmpty()){
            jynMap = jynData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jenData != null && !jenData.isEmpty()){
            jenMap = jenData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jsnData != null && !jsnData.isEmpty()){
            jsnMap = jsnData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }

        if(jsinData != null && !jsinData.isEmpty()){
            jsinMap = jsinData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }
        if(jwnData != null && !jwnData.isEmpty()){
            jwunMap = jwnData.stream().collect(Collectors.toMap(JcQueryDo::getCity, JcQueryDo::getValue));
        }

        //查询16地市
        List<LowArea> cityList = lowEffCompanyMapper.selectCityInfo(jcQueryParam);

        Map<String, String> cityMap = cityList.stream().collect(Collectors.toMap(LowArea::getAreaCode, LowArea::getBaseName,(oldValue, newValue) -> oldValue, TreeMap::new));

        List<JcResVo> result = new ArrayList<>();

        for(Map.Entry<String,String> temp : cityMap.entrySet()){
            String value = temp.getValue();

            JcResVo tempJcRes = new JcResVo();
            tempJcRes.setCity(value);
            tempJcRes.setJyn(jynMap.get(value));
            tempJcRes.setJen(jenMap.get(value));
            tempJcRes.setJsn(jsnMap.get(value));
            tempJcRes.setJsin(jsinMap.get(value));
            tempJcRes.setJwn(jwunMap.get(value));
            result.add(tempJcRes);
        }
        return result;
    }

    /**
     * 查询单位用地销售Charts
     *
     * @param jcQueryParam
     * @return
     */
    @Override
    public Map<String, Object> queryDwysxssrCharts(JcQueryParam jcQueryParam) {
        //查询YiYear上一年的数据，为了计算同比
        Integer preYear = Integer.valueOf(jcQueryParam.getWuYear()) - 1;
        JcQueryDo preData = lowEffCompanyMapper.queryDwysxssrCharts(String.valueOf(preYear),jcQueryParam);

        //查询近一年单位用地税收监测
        JcQueryDo jynData = lowEffCompanyMapper.queryDwysxssrCharts(jcQueryParam.getYiYear(),jcQueryParam);
        //查询近二年单位用地税收监测
        JcQueryDo jenData = lowEffCompanyMapper.queryDwysxssrCharts(jcQueryParam.getLiangYear(),jcQueryParam);
        //查询近三年单位用地税收监测
        JcQueryDo jsnData = lowEffCompanyMapper.queryDwysxssrCharts(jcQueryParam.getSanYear(),jcQueryParam);
        JcQueryDo jsinData = lowEffCompanyMapper.queryDwysxssrCharts(jcQueryParam.getSiYear(),jcQueryParam);
        JcQueryDo jwnData = lowEffCompanyMapper.queryDwysxssrCharts(jcQueryParam.getWuYear(),jcQueryParam);

        List<String> xAxis = new ArrayList<>();
        List<String> zzCharts = new ArrayList<>();
        List<BigDecimal> tb = new ArrayList<>();
        if(jynData != null){
            String yiYear = jcQueryParam.getYiYear();
            xAxis.add(yiYear);
            String value = jynData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jenData == null ? BigDecimal.ZERO : new BigDecimal(jenData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String yiYear = jcQueryParam.getYiYear();
            xAxis.add(yiYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jenData != null){
            String liangYear = jcQueryParam.getLiangYear();
            xAxis.add(liangYear);
            String value = jenData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jsnData == null ? BigDecimal.ZERO : new BigDecimal(jsnData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String liangYear = jcQueryParam.getLiangYear();
            xAxis.add(liangYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jsnData != null){
            String sanYear = jcQueryParam.getSanYear();
            xAxis.add(sanYear);
            String value = jsnData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue =  jsinData == null ? BigDecimal.ZERO : new BigDecimal(jsinData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }
        }else{
            String sanYear = jcQueryParam.getSanYear();
            xAxis.add(sanYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jsinData != null){
            String yiYear = jcQueryParam.getSiYear();
            xAxis.add(yiYear);
            String value = jsinData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = jwnData == null ? BigDecimal.ZERO : new BigDecimal(jwnData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }

        }else{
            String yiYear = jcQueryParam.getSiYear();
            xAxis.add(yiYear);
            zzCharts.add("0");
            tb.add(null);
        }

        if(jwnData != null){
            String wuYear = jcQueryParam.getWuYear();
            xAxis.add(wuYear);
            String value = jwnData.getValue();
            zzCharts.add(value);

            BigDecimal currentValue = new BigDecimal(value);
            BigDecimal preValue = preData == null ? BigDecimal.ZERO :  new BigDecimal(preData.getValue());
            if(preValue.compareTo(BigDecimal.ZERO) == 0){
                tb.add(null);
            }else{
                BigDecimal zf = currentValue.subtract(preValue).divide(preValue, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                tb.add(zf);
            }

        }else{
            String wuYear = jcQueryParam.getWuYear();
            xAxis.add(wuYear);
            zzCharts.add("0");
            tb.add(null);
        }

        Map<String,Object> result = new HashMap<>();
        result.put("X",xAxis);
        result.put("zzCharts",zzCharts);
        result.put("tb",tb);
        return result;
    }


    /**
     * 查询低效能企业
     *
     * @param params
     * @return
     */
    @Override
    public List<JcResVo> queryLowerCompanyInfoByCd(LowEfficiencyBenefitEvaluation params) {
        params.setStatus("5");
        List<JcResVo> list = lowEffCompanyMapper.queryLowerCompanyInfoByCd(params);
        return list;
    }
}
